import java.util.*;

public class Test16 {
    public static void main03(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNext()) { // 注意 while 处理多个 case
            String s = in.nextLine();
            int b = in.nextInt();
            int purLeft=-1;
            int sum = 0;
            for (int left = 0, right = 0; right < s.length()-b; right++) {
                int count=0;
                // 进入窗口
                if (s.charAt(right) == 'G' ) {
                    left=right;
                    count = judge(s,left,right+b);

                }
                if(sum == 0 && count !=0){
                    sum=count;
                    purLeft=left;
                }
                if(sum < count){
                    purLeft=left;
                }
            }
            int i=purLeft;
            while(i<=purLeft+b){
                int len=0;
                if(s.charAt(i) == 'G' && i< s.length()-1 && s.charAt(i+1) == 'C'){
                        for(int j=i;j<i+b;j++){
                            len++;
                            System.out.print(s.charAt(j));
                        }
                }
                if(len == b){
                    break;
                }
                i++;
            }
        }
    }
    public static int judge(String s,int left,int right){
        int sum=0;
        for(int i=left;i<right;i++){
            if(s.charAt(i) == 'G'){
                if(i<right && s.charAt(i+1) == 'C'){
                    sum++;
                }
            }
        }
        return sum;
    }




    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int a = in.nextInt();
            int b = in.nextInt();
            int count = 0;
            for (int i = a; i <= b; i++) {
                if (is(i)) {

                    count++;
                } else {
                    int len = 0;
                    int tmp = i;
                    while (tmp != 0) {
                        len++;
                        tmp /= 10;
                    }
                    int[] arr = new int[len];
                    int j=0;
                    tmp=i;
                    while (tmp != 0) {
                        arr[j++]=tmp%10;
                        tmp /= 10;
                    }
                    boolean m=false;
                    for(int x=0;x<j;x++){

                        for(int y=0;y<j;y++){
                            if(y!=x) {
                                if ( arr[y] !=0 &&is(arr[x] + arr[y] * 10)) {
                                    count++;
                                    m = true;
                                    break;
                                } else {
                                    if (arr[x] !=0 &&is(arr[y] + arr[x] * 10)) {
                                        count++;
                                        m = true;
                                        break;
                                    }
                                }
                            }
                        }
                        if(m){
                            break;
                        }
                    }
                }
            }
            System.out.println(count);
        }

    }
    // 判断质数
    public static boolean is(int a) {
        if (a == 1 || a == 2) {
            return true;
        }
        for (int i = 2; i < a; i++) {
            if (a % i == 0) {
                return false;
            }
        }
        return true;
    }










    public static void main01(String[] args) {
        String str="A%sC%sE";
        char[] arg=new char[]{'B','D','F'};
        System.out.println(formatString(str, arg).toString());
    }
    public static String formatString (String str, char[] arg) {
        StringBuilder s=new StringBuilder();
        Queue<Character> queue=new LinkedList<>();
        for(char ch:str.toCharArray()){
            queue.add(ch);
        }
        int len=0;
        int n=queue.size();
        int i=0;
        while(i<n && !queue.isEmpty()){

            if(queue.peek() == '%'){
                queue.poll();
                queue.poll();
                s.append(arg[len++]);

            }else{
                s.append(queue.poll());
            }
            i++;
        }
        if(len < arg.length){
            for(int j=len;j<arg.length;j++){
                s.append(arg[j]);
            }
        }
        return s.toString();
    }
}
